<cfparam name="Order_ID" type="numeric" default="0" />
<cfparam name="returnUI" type="string" default="orders" />

<cfscript>
	order = request.orderGateway.get(Order_ID = Order_ID);
	institution = "";
</cfscript>

<cfif order.getOrder_ID() gt 0>
	<cfscript>
		statuses = request.Base.getOrderStatuses();
		if (order.getInstitution_Type() eq "high school") {
			institution = request.gateway.call(objType = "storedProcedure", obj = "readHighSchool", High_School_ID = order.getInstitution_ID());
			order.setInstitution(institution.High_School);
		} else if (order.getInstitution_Type() eq "college university") {
			institution = request.gateway.call(objType = "storedProcedure", obj = "readInstitution", Institution_ID = order.getInstitution_ID());
			order.setInstitution(institution.Institution);
		};
		orderProducts = request.orderProductGateway.query(Order_ID = order.getOrder_ID(), Deleted = 0);
		tracking = request.trackingGateway.query(Order_ID = order.getOrder_ID(), Deleted = 0);
	</cfscript>

	<cfset trackingCodes = ArrayNew(1) />
	<cfloop query="tracking">
		<cfset ArrayAppend(trackingCodes, Tracking_Code) />
	</cfloop>
	<cfform id="orderForm" name="orderForm" action="index.cfm" role="form"  method="post">
		<input type="hidden" name="action" value="saveOrderStatus" />
		<cfoutput>
			<input type="hidden" name="ui" value="#ui#" />
			<input type="hidden" name="view" value="#view#" />
			<input type="hidden" id="Order_ID" name="Order_ID" value="#order.getOrder_ID()#" />
			<table width="100%">
				<tr valign="top">
					<td width="25%">
						<h4>Status</h4>
						<p>#order.getStatus()#</p>
						<h4>Order Date</h4>
						<p>#DateFormat(order.getDate_Created(), "mmmm d, yyyy")#</p>
						<h4>Approved Date</h4>
						<p>
							<cfif IsDate(order.getApproved_Date())>
								#DateFormat(order.getApproved_Date(), "mmmm d, yyyy")#
							<cfelse>
								Not approved
							</cfif>
						</p>
						<h4>Shipped Date</h4>
						<p>
							<cfif IsDate(order.getShipped_Date())>
								#DateFormat(order.getShipped_Date(), "mmmm d, yyyy")#
							<cfelse>
								Not shipped
							</cfif>
						</p>
					</td>
					<td width="25%">
						<h4>Ship To</h4>
						<p>#order.getInstitution()#<br />
						#order.getAddress1()#<br />
						<cfif Len(order.getAddress2()) gt 0>
							#order.getAddress2()#<br />
						</cfif>
						#order.getCity()#, #order.getState()# #order.getZip_Code()#</p>
						<h4>Ordered By</h4>
						<p>#order.getFirst_Name()# #order.getLast_Name()#<br />
						#order.getEmail()#<br />
						#order.getPhone()#<cfif Len(order.getExtension()) gt 0> x #order.getExtension()#</cfif></p>
					</td>
					<td width="25%">
						<h4>Shipping Instructions</h4>
						<cfif Len(order.getShipping_Instructions()) gt 0>
							<p>#order.getShipping_Instructions()#</p>
						<cfelse>
							<p>None</p>
						</cfif>
						
						<h4>Tracking Code</h4>
						<p>
							<cfif ArrayLen(trackingCodes) gt 0>
								#trackingCodes[1]#<br />
							<cfelse>
								None
							</cfif>
						</p>
					</td>
					<td width="25%">
						<h4>Notes</h4>
						<cfif Len(order.getShared_Notes()) gt 0>
							<p>#order.getShared_Notes()#</p>
						<cfelse>
							<p>None</p>
						</cfif>
						<cfif IsUserLoggedIn()>
							<h4>Private Notes</h4>
							<p>
								<cfif IsDate(order.getPrivate_Notes())>
									<p>#order.getPrivate_Notes()#</p>
								<cfelse>
									None
								</cfif>
							</p>
						</cfif>
					</td>
				</tr>
			</table>
			<div class="row">
				<div class="col-lg-12">
					<h4>Items</h4>
					<table class="table table-striped table-bordered">
						<thead>
							<tr>
								<th>ID</th>
								<th>Item</th>
								<th>Quantity Ordered</th>
								<th>Quantity Shipped</th>
							</tr>
						</thead>
						<tbody>
							<cfloop query="orderProducts">
								<tr>
									<td>#ID#</td>
									<td>#Product#</td>
									<td>#Quantity#</td>
									<td>#Quantity_Shipped#</td>
								</tr>
							</cfloop>
						</tbody>
					</table>
				</div>
			</div>
		</cfoutput>
	</cfform>
</cfif>